package no18.javaio;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * 读取一个文件内容
 * 
 * @author gao
 * 
 */
public class BufferedInputFile {
	private final static String FILE_NAME = "D:/work/project/complex/complex.thinkinjava/src/main/java/no18/javaio/test.txt";

	public static String read(String fileName) throws IOException {
		// BufferedReader 缓冲输入文件,以提高性能
		BufferedReader in = new BufferedReader(new FileReader(fileName));
		String s;
		StringBuilder sb = new StringBuilder();
		// BufferedReader 具体readLine()方法
		while ((s = in.readLine()) != null) {
			// 加上换行符
			sb.append(s + "\n");
		}
		// 关闭流
		in.close();
		return sb.toString();
	}

	public static void main(String[] args) throws IOException {
		System.out.println(read(FILE_NAME));
	}
}
